﻿using Scap.Data;
using Scap.Info;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Scap.Core
{
    public class DeviceTaskHandlerStatus : DeviceTaskHandler
    {

        public DeviceTaskHandlerStatus(DeviceTaskModel model)
            : base(model)
        {

        }

        

        public override void Run()
        {
            UpdateStatus();
        }



        private void UpdateStatus()
        {
            try
            {                
                _logger.Info("{0} | Actualizando estado...", _device.IpAddress);
                ScapData db = new ScapData();
                db.Entry(_device).State = System.Data.EntityState.Modified;
                db.SaveChanges();
                _logger.Info("{0} | Actualizando estado...[OK]", _device.IpAddress);
            }
            catch (Exception ex)
            {
                _logger.Error("{0} | Actualizando estado...[FALLO]: {1}", _device.IpAddress, ex.Message);
            }
        }
    }
}
